﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class NewBooks : System.Web.UI.Page
{
    BookDAO bookDao;
    BookStoreDataContext bs;
    protected void Page_Load(object sender, EventArgs e)
    {
        bookDao = new BookDAO();
         bs = new BookStoreDataContext();
        drpCategory.DataSource = bs.categories.GetNewBindingList();

        drpCategory.DataTextField = "name";
        drpCategory.DataValueField = "category_id";
        drpCategory.DataBind();
    }
    
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        if(this.IsValid){
            item i = new item()
            {
                category_id = int.Parse(drpCategory.SelectedItem.Value.ToString()),
                author = txtAuthor.Text.Trim(),
                name = txtName.Text.Trim(),
                notes = taNote.InnerText
            };
            bs.items.InsertOnSubmit(i);
            bs.SubmitChanges();
        }
        
    }
}